package net.mcfire.aliyunplugin;

import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;

import java.io.File;
import java.io.IOException;

public class BungeeAdapter extends Plugin implements ConfigLoader {

    @Override
    public void onLoad() {
        AliyunPlugin.bungee = true;
        AliyunPlugin.plugin = new AliyunPlugin(this, getLogger());
        AliyunPlugin.plugin.onLoad();
    }

    @Override
    public void onEnable() {
        AliyunPlugin.plugin.onEnable();
    }

    @Override
    public void reloadConfig() throws IOException {
        Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File("/nas/conf/AliyunPlugin.yml"));
        AliyunPlugin.api_region_id = config.getString("aliyun.api-region");
        AliyunPlugin.ecs_region_id = config.getString("aliyun.ecs-region");
        AliyunPlugin.aliyunAccessKeyId = config.getString("aliyun.akid");
        AliyunPlugin.aliyunAccessKeySecret = config.getString("aliyun.aks");
        HTTP.api_endpoint = config.getString("api.endpoint");
        HTTP.api_key = config.getString("api.key");
        AliyunPlugin.aliyunLogEndpoint = config.getString("aliyun.logging.endpoint");
        AliyunPlugin.aliyunLogProject = config.getString("aliyun.logging.project");
        AliyunPlugin.aliyunLogStore = config.getString("aliyun.logging.store");
    }
}
